# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>

# when changing _kver/_krel make sure _rel=0
_kver=6.6.9
_krel=0
_flavor="$FLAVOR"
[ -z "$_flavor" ] && _flavor=lts
# when changing _commit we *must* bump _rel
_commit=f93db734666f75ebf65e44ceb943c19b598b1647
_rel=0
_kpkg=linux-$_flavor

pkgname=rtl8821ce-lts
pkgver="$_kver"
pkgrel=$((_krel + _rel))
pkgdesc="Wifi drivers for Realtek 8821ce"
url="https://github.com/tomaspinho/rtl8821ce"
# disable til we have figured out if it is needed with 6.1
#arch="x86_64 x86" # Only builds on these platforms
license="GPL-2.0-only"
makedepends="linux-lts-dev"
options="!check"
source="$pkgname-$_commit.tar.gz::https://github.com/tomaspinho/rtl8821ce/archive/$_commit.tar.gz
	kernel-5.15.patch"
builddir="$srcdir/rtl8821ce-$_commit"

prepare() {
	default_prepare

	if [ -z "$FLAVOR" ]; then
		(
			. "$startdir"/../../main/linux-$_flavor/APKBUILD
			[ "$_kver" != "$pkgver" ] && die "please update _kver to $pkgver"
			[ "$_krel" != "$pkgrel" ] && die "please update _krel to $pkgrel"
			return 0
		)
	fi
}

build() {
	make KVER=$_kver-$_krel-$_flavor \
		MODULES_DIR="/lib/modules/$_kver-$_krel-$_flavor"
}

package() {
	install -Dm0644 8821ce.ko \
		"$pkgdir"/lib/modules/$_kver-$_krel-$_flavor/extra/8821ce.ko
}

sha512sums="
7be780841fe606cc9bd37a5e66cc284cc8f6b498068b9117942d11e4e555fbf8cadfe754c34f300debc00e2f72bb74e91ff864f7a7df5c637ff62e097ffef33b  rtl8821ce-lts-f93db734666f75ebf65e44ceb943c19b598b1647.tar.gz
62cdebd4f407e63365f255670aeafc64894420cbca2f151dd97642c31de205295d038300d9d3fcb3c7a9dbe580cf6d21029732aea36feb396c3455b5a7dce706  kernel-5.15.patch
"
